home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / BODI / IFOUT.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  15.7 KB  |  631 lines

  1. /************************************************************************/
  2. /* HISTORY:                                */
  3. /*                                     */
  4. /* 11/07/89 -   Substitute new routines from fast.s to replace          */
  5. /*        zvalue(),world_rc_x() and world_rc_y()            */
  6. /*        We keep the world_rc_x() and world_rc_y() functions     */
  7. /*        just in case some obj file calls it.            */
  8. /*        -    blt_char() - worldy replacements            */
  9. /*        -   bar() - worldx/worldy replacements            */
  10. /*        -   world_convert() - worldx/worldy replacements        */
  11. /*        -   world_rc_x() - comment out code. Replace with worldx()  */
  12. /*        -   world_rc_y() - comment out code. Replace with worldy()  */
  13. /*        -   zvalue()     - comment out. replace with fast.s version */
  14. /************************************************************************/
  15. #include    <obdefs.h>
  16. #include    <gemdefs.h>
  17. #include    "comp.h"
  18. #include    "bitmap.h"        /* defs structure bit_map_type    */
  19. #include    "cache.h"        /* defs cache structure        */
  20.  
  21. /*
  22.     Local Definitions
  23. */
  24. #ifndef        FALSE
  25. #define        FALSE        0
  26. #endif
  27. #ifndef        TRUE
  28. #define        TRUE        1
  29. #endif
  30. #define        OFF        0
  31. #define        ON        1
  32. #define        H_PICA        216    /* X unit used in world Coord.    */
  33. #define        V_PICA        192    /* Y unit used in world Coord.    */
  34. #define        ULG        unsigned long
  35.  
  36. /*    Device Type = sdevm    */
  37. #define        DNUM        4    /* number of graphics devices    */
  38. #define        SLOR        0    /* Low    Res    320  x 200     */
  39. #define        SMDR        1    /* Medium Res    640  x 200     */
  40. #define        SHIR        2    /* High   Res    640  x 400    */
  41. #define        PRNT        3    /* Laser  Ptr    2400 x 3180    */
  42.  
  43. /*
  44.     Externals
  45. */
  46. extern    struct bit_map_type
  47.             *fm_char();    /* IFont char building function    */
  48. extern    struct slvll    *slv;        /* slave list pointer        */
  49. extern    int        shandle;    /* graphics output handle    */
  50. extern    FDB        *orect_MFDB;    /* output rectangle    MFDB    */
  51. extern    FDB        char_MFDB;    /* Intellifont        MFDB    */
  52. extern    unsigned long    last_y;
  53. extern    int        clip_X0;    /* output rectangle clip X0    */
  54. extern    int        clip_X1;    /* output rectangle clip X1    */
  55. extern    int        clip_Y0;    /* output rectangle clip Y0    */
  56. extern    int        clip_Y1;    /* output rectangle clip Y1    */
  57.  
  58. extern int mu_array[];             /* CS mu conversion array       */
  59. unsigned     lastpixy;
  60. unsigned    lastmuy;
  61.  
  62. /*
  63.     Conflict resolution
  64. */
  65. unsigned    get_argument();
  66.  
  67. /*
  68.     Device dependent tables
  69. */
  70. unsigned xdpi[DNUM]    = {        /* Device Xdots/inch resolution    */
  71. /* LOW */    40,            /* 320 x 200    */
  72. /* MED */    80,            /* 640 x 200    */
  73. /* HIG */    80,            /* 640 x 400    */
  74. /* PRT */    300            /* 2400x3180    */
  75. };
  76. unsigned ydpi[DNUM]    = {        /* Device Ydots/inch resolution    */
  77. /* LOW */    40,            /* 320 x 200    */
  78. /* MED */    40,            /* 640 x 200    */
  79. /* HIG */    80,            /* 640 x 400    */
  80. /* PRT */    300            /* 2400x3180    */
  81. };
  82.  
  83. /*
  84.     Module globals
  85. */
  86. struct packet_type    userpacket;/* IFont character packet    */
  87. static    struct {
  88.     unsigned    x    ;
  89.     unsigned    y    ;
  90.     unsigned    psiz    ;
  91.     unsigned    ssiz    ;
  92.     unsigned    font    ;
  93.     unsigned    reverse    ;
  94.     unsigned    rev_top    ;
  95.     unsigned    rev_bot    ;
  96. }    present            ;/* present slave scan struct    */
  97. static    struct {
  98.     unsigned    px    ;
  99.     unsigned    py    ;
  100.     unsigned    psiz    ;
  101.     unsigned    ssiz    ;
  102.     unsigned    font    ;
  103.     char        ch    ;
  104. }    rvo            ;/* Rev Video save char struct    */
  105. static    struct    bit_map_type
  106.         Greek        ;/* IFont struct. for Greeking    */
  107. unsigned    H_MARGIN    ;/* Horizontal    Left    margin    */
  108. unsigned    V_MARGIN    ;/* Vertical    Top    margin    */
  109. unsigned    zrat        ;/* zoom ratio (100 = 100%)..    */
  110. unsigned    sdevm        ;/* Current device mode        */
  111.  
  112.  
  113. /****************************************************************
  114. *    Slave Output Handler                    *
  115. *    Desc :    This routine scans through the slave command     *
  116. *    buffer list to the end. It also calls the appropriate    *
  117. *    function to execute these commands.            *
  118. *    Calling convention :    show_slv()            *
  119. ****************************************************************/
  120. show_slv()
  121. {
  122.     struct    slvll    *pslv        ;/* present slave list pointer    */
  123.     unsigned char    *buffer_ptr    ;
  124.     unsigned    code        ;
  125.     int        index = 1    ;
  126.  
  127.   pslv = slv                ;/* set to beginning of list    */
  128.   do {                     /* for whole slave list...    */
  129.     buffer_ptr = pslv->bufptr        ;/* set slave buffer pointers    */
  130.     do {                 /* for whole buffer...        */
  131.     code = get_argument(buffer_ptr)    ;/* get the encoded word    */
  132.     if (!(code & 0xFF00))         /* check if NULL command    */
  133.         index = 1        ;
  134.     else
  135.     if ((code & 0x8080) == 0x8080)     /* check if TYP command    */
  136.         index = exe_command(buffer_ptr);
  137.     else
  138.     if (code & 0x8000)         /* check if long char format    */
  139.         index = exe_long_char(buffer_ptr);
  140.     if (index > 0)
  141.         buffer_ptr += index    ;
  142.     } while (index > 0)            ;/* continue until index < 0    */
  143.   } while (pslv = pslv->fptr)        ;/* until end of list...    */
  144. }
  145.  
  146. /****************************************************************
  147. *    Function Name :        exe_long_char()            *
  148. *    Desc :    This routine executes a long char command    *
  149. *    Calling convention :    exe_long_char(buff_ptr)        *
  150. *        unsigned char    *buff_ptr : pointer to command     *
  151. ****************************************************************/
  152. exe_long_char(buffer_ptr)
  153. unsigned char    *buffer_ptr    ;
  154. {
  155.     char     dchar        ;
  156.     unsigned position    ;
  157.  
  158.     dchar     = *(buffer_ptr++) & 0X7F;    /* get the character    */
  159.     position = get_argument(buffer_ptr);    /* get X escapement    */
  160.     rvo.px     = present.x        ;
  161.     present.x = position + H_MARGIN    ;    /* set X text position    */
  162.     if (present.reverse) {            /* check if RVO ON    */
  163.         rev_char()        ;
  164.         rvo.ch     = dchar    ;
  165.         rvo.psiz = present.psiz    ;
  166.         rvo.ssiz = present.ssiz    ;
  167.         rvo.font = present.font    ;
  168.     }
  169.     else    disp_char(dchar,present.x,present.y);
  170.     rvo.py    = present.y        ;
  171.     return(3);
  172. }
  173.  
  174. /****************************************************************
  175. *    Function Name :        rev_char()            *
  176. *    Desc :    This routine displays a reverse video char    *
  177. *    Calling convention :    rev_char()            *
  178. ****************************************************************/
  179. rev_char()
  180. {
  181.     int    x, y, w, h;
  182.  
  183.     if (rvo.px > present.x) {
  184.         x = present.x            ;
  185.         w = rvo.px - present.x        ;
  186.     }
  187.     else {
  188.         x = rvo.px            ;
  189.         w = present.x - rvo.px        ;
  190.     }
  191.     y = rvo.py - present.rev_top        ;/* cal bar position    */
  192.     if (y < 0) y = 0            ;
  193.     h = rvo.py + present.rev_bot - y    ;
  194.     if (w > 0) {
  195.         bar(x,y,w,h)            ;/* display black bar    */
  196.         if (rvo.ch) {
  197.           setptsz(rvo.psiz)        ;
  198.           setssize(rvo.ssiz)         ;
  199.           setafont(rvo.font)        ;
  200.           disp_char(rvo.ch,rvo.px,rvo.py);
  201.           setptsz(present.psiz)        ;
  202.           setssize(present.ssiz)    ;
  203.           setafont(present.font)    ;
  204.         }
  205.     }
  206. }
  207.  
  208. /************************************************************************
  209. *    Function Name :        get_argument()                *
  210. *    Desc :    This function gets the command argument and converts    *
  211. *    it to unsigned value.                        *
  212. *    Calling convention :    get_argument(value_ptr)            *
  213. *        unsigned char *value_ptr : pointer to command argument    *
  214. *    Return value :        unsigned value                *
  215. ************************************************************************/
  216. unsigned get_argument(value)
  217. unsigned char *value    ;
  218. {
  219.     union {
  220.         unsigned char    byt[2]    ;
  221.         unsigned    val    ;
  222.     } w;
  223.  
  224.     w.byt[0] = *value++,
  225.     w.byt[1] = *value        ;/* combine two together     */
  226.     return(w.val)            ;/* return the value         */
  227. }
  228.  
  229. /****************************************************************
  230. *    Function Name :        exe_command()            *
  231. *    Desc :    This routine execute the slave command        *
  232. *    Calling convention : len = exe_command(cmd_ptr)        *
  233. *        unsigned char    *cmd_ptr : pointer to command    *
  234. *    Return value    :    int command length        *
  235. ****************************************************************/
  236. exe_command(buffer_ptr)
  237. unsigned char     *buffer_ptr    ;
  238. {
  239.     unsigned char    command    ;
  240.     unsigned    argument;
  241.     int    cmd_len = 3    ;
  242.  
  243. command  = *(buffer_ptr++) & 0X7F        ;/* get command number     */
  244. argument = get_argument(buffer_ptr)        ;/* get    command arg    */
  245. argument &= 0X7FFF                ;/* mask the high bit    */
  246. switch(command) {
  247. case( 3)    :                 /* REVERSE TYPE    */
  248.     if (present.reverse)
  249.         rev_char()            ;
  250.     else    rvo.py    = present.y        ;
  251.     present.reverse = argument        ;/* set reverse type    */
  252.     if (!argument) rvo.ch = 0        ;
  253.     break                    ;
  254. case( 7)    :                 /* POINT SIZE CMD    */
  255.     setptsz(present.psiz = argument)    ;/* set char height    */
  256. case( 8)    :                 /* SET SIZE CMD    */
  257.     setssize(present.ssiz = argument)     ;/* set char width    */
  258.     break                    ;
  259. case( 9)    :                 /* VERTICAL MOVE DOWN    */
  260.     present.y += argument            ;/* adjust position    */
  261.     break                    ;
  262. case(10)    :                 /* VERTICAL MOVE UP    */
  263.     present.y -= argument            ;/* adjust position    */
  264.     break                    ;
  265. case(11)    :                 /* HORIZONTAL POSITION */
  266.     if (present.reverse)
  267.         rvo.px = present.x        ;
  268.     present.x = argument + H_MARGIN        ;/* adjust position    */
  269.     break                    ;
  270. case(15)    :                 /* SLANT MODE        */
  271.     break                    ;
  272. case(16)    :                 /* REVERSE TOP        */
  273.     present.rev_top = argument        ;/* set rev_top value    */
  274.     break                    ;
  275. case(17)    :                 /* REVERSE BOTTOM    */
  276.     present.rev_bot = argument        ;/* set rev_bot value    */
  277.     break                    ;
  278. case(22)    :                 /* SET FONT        */
  279.     setafont(present.font = argument)    ;
  280.     cmd_len = 9                ;
  281.     break                    ;
  282. case(27)    :                 /* MOVE HOR RIGHT    */
  283.     present.x += argument            ;/* adjust position    */
  284.     break                    ;
  285. case(28)    :                 /* MOVE HOR. LEFT    */
  286.     present.x -= argument            ;/* adjust position    */
  287.     break                    ;
  288. case(SLVEOD)    :                 /* END OF SLAVE DATA    */
  289. case(SLVEOB)    :                 /* END OF SLAVE BLOCK    */
  290.     cmd_len = -1                ;/* stop scanning code    */
  291.     break                    ;
  292. case(31)    :                 /* VERTICAL POSITION    */
  293.     present.y = argument + V_MARGIN        ;/* adjust position    */
  294.     break                    ;
  295. }
  296. return(cmd_len)                    ;/* return cmmnd length    */
  297. }
  298.  
  299. /*
  300.     Function to initialize IFont System
  301. */
  302. initftsys(mod)
  303. int    mod;
  304. {
  305.     if (!fm_init(mod)            /* set up Intellifont    */
  306.      || !fm_outdevice(0,xdpi[sdevm],ydpi[sdevm])    /* both screen    */
  307.      || !fm_outdevice(1,xdpi[PRNT],ydpi[PRNT]))    /* and printer    */
  308.         return(1);
  309.     else {    newdev(0);
  310.         return(0);
  311.     }
  312. }
  313.  
  314. /*
  315.     Function to set IFont system to new device
  316. */
  317. newdev(dev)
  318. int    dev;
  319. {
  320.     userpacket.p_cd.point_size    = 96;
  321.     userpacket.p_cd.set_size    = 96;
  322.     userpacket.p_cd.rotate_angle    = 0;
  323.     userpacket.p_cd.bold        = 0;
  324.     userpacket.p_cd.devnum        = dev;
  325.     userpacket.p_cd.font_id        = 1;
  326. }
  327.  
  328. /*
  329.     Function to set IFont user packet to new point size
  330. */
  331. setptsz(val)
  332. int    val;
  333. {
  334.     ssize(&userpacket.p_cd.point_size,val);
  335. }
  336.  
  337. /*
  338.     Function to set IFont user packet to new set size
  339. */
  340. setssize(val)
  341. int    val;
  342. {
  343.     ssize(&userpacket.p_cd.set_size,val);
  344. }
  345.  
  346. ssize(size,val)
  347. unsigned *size, val;
  348. {
  349.     *size = zvalue(val);
  350. }
  351.  
  352. /*
  353.     Function to set IFont user packet to new font number
  354. */
  355. setafont(val)
  356. int    val;
  357. {
  358.     userpacket.p_cd.font_id    = val;
  359. }
  360.  
  361. /*
  362.     Function to setup Greeking bitmap structure.
  363. */
  364. setupGreek()
  365. {
  366.     Greek.width    = 1;
  367.     Greek.depth    = sdevm == SMDR ? 2:4;
  368.     Greek.left_indent = 0;
  369.     Greek.base_pix    = Greek.depth;
  370.     Greek.new_lsb    = 0;
  371.     Greek.bm[0]    = 0x5000;    /* Greeking character Bit Map    */
  372.     Greek.bm[1]    = 0xA000;    /* Medium Res. only use 2 words    */
  373.     Greek.bm[2]    = 0x5000;
  374.     Greek.bm[3]    = 0xA000;
  375. }
  376.  
  377. /*
  378.     IFont character display
  379. */
  380. disp_char(dchar,dx,dy)
  381. unsigned char    dchar;
  382. unsigned    dx, dy;
  383. {
  384.     struct bit_map_type    *bmp_ptr;
  385.  
  386.     if (!dchar || dchar > 118)
  387.         return;
  388.     if (userpacket.p_cd.point_size    < 40 &&
  389.         userpacket.p_cd.set_size    < 40)    /* Greeking < 5 points    */
  390.         bmp_ptr = &Greek;
  391.     else {
  392.         userpacket.flash_pos = dchar - 1;
  393.         bmp_ptr = fm_char(&userpacket);
  394.     }
  395.     if (bmp_ptr) blt_char(bmp_ptr, dx, dy);
  396. }
  397.  
  398. /********************************/
  399. /*    grect_to_array        */
  400. /********************************/
  401. grect_to_array(area, array)    /* convert x,y,w,h to upr lt x,y and    */
  402. GRECT     *area;            /*              lwr rt x,y    */
  403. unsigned *array;
  404. {
  405.     *array++= area->g_x;
  406.     *array++= area->g_y;
  407.     *array++= area->g_x + area->g_w - 1;
  408.     *array    = area->g_y + area->g_h - 1;
  409. }
  410.  
  411. /********************************/
  412. /*    raster_operation    */
  413. /********************************/
  414. rast_op(mode, s_area, s_MFDB, d_area, d_MFDB)    /* bit block level Xfer    */
  415. unsigned mode;
  416. GRECT    *s_area, *d_area;
  417. FDB    *s_MFDB, *d_MFDB;
  418. {
  419.     unsigned pxy[8];
  420.  
  421.     grect_to_array(s_area, pxy);
  422.     grect_to_array(d_area, &pxy[4]);
  423.     vro_cpyfm(shandle,mode,pxy,s_MFDB,d_MFDB);
  424. }
  425.  
  426. /********************************/
  427. /*    IFont char Blit        */
  428. /********************************/
  429. blt_char(bptr,x,y)
  430. struct bit_map_type    *bptr;
  431. unsigned        x, y;
  432. {
  433.     GRECT    s, d;
  434.     int    ref, IFcw, IFch;
  435.  
  436.     ref    = world_convert(x);
  437.     d.g_x    = ref + (bptr->new_lsb >> 4) - bptr->left_indent;
  438.     IFcw    = bptr->width << 4;
  439.     if (d.g_x < clip_X0) {
  440.         s.g_x = clip_X0 - d.g_x;
  441.         d.g_x = clip_X0;
  442.     }
  443.     else    s.g_x = 0;
  444.     ref    = IFcw - s.g_x;
  445.     if (ref <= 0)    return;
  446.     if ((d.g_w = clip_X1 - d.g_x) >= ref)
  447.         d.g_w = s.g_w = ref;
  448.     else
  449.     if (d.g_w <= 0) return;
  450.     else    s.g_w = d.g_w;
  451.         if(y == lastmuy)        /* If we're on the same line we.. */
  452.             ref = lastpixy;        /* don't have to recalculate y .. */
  453.         else                /* pixel position          */
  454.     {
  455.             lastmuy = y;
  456. /*        ref = lastpixy = world_rc_y(y);   CJG 11/07/89 */
  457.         ref = lastpixy = worldy(y);
  458.     }
  459.     d.g_y    = ref - bptr->base_pix;
  460.     IFch    = bptr->depth;
  461.     if (d.g_y < clip_Y0) {
  462.         s.g_y = clip_Y0 - d.g_y;
  463.         d.g_y = clip_Y0;
  464.     }
  465.     else    s.g_y = 0;
  466.     ref    = IFch - s.g_y;
  467.     if (ref <= 0)    return;
  468.     if ((d.g_h = clip_Y1 - d.g_y) >= ref)
  469.         d.g_h = s.g_h = ref;
  470.     else
  471.     if (d.g_h <= 0) return;
  472.     else    s.g_h = d.g_h;
  473.  
  474.     char_MFDB.fd_addr    = (ULG)bptr->bm;
  475.     char_MFDB.fd_w        = IFcw;
  476.     char_MFDB.fd_h        = IFch;
  477.     char_MFDB.fd_wdwidth    = bptr->width;
  478.     rast_op((present.reverse) ? 4:7,&s,&char_MFDB,&d,orect_MFDB);
  479. }
  480.  
  481. /****************************************/
  482. /*    Draw Bar using world values    */
  483. /****************************************/
  484. bar(x,y,w,h)
  485. unsigned x,y,w,h;
  486. {
  487.     GRECT    rul;
  488.     int    ref;
  489. /*
  490.     rul.g_x = world_rc_x(x);
  491.     w    = world_rc_x(w) + 1;
  492. */
  493.     rul.g_x = worldx(x);        /* cjg 11/07/89 */
  494.     w     = worldx(w) + 1;
  495.  
  496.     if (rul.g_x < clip_X0) {
  497.         ref = clip_X0 - rul.g_x;
  498.         rul.g_x = clip_X0;
  499.     }
  500.     else    ref = 0;
  501.     w    -= ref;
  502.     if (w <= 0)    return;
  503.     if ((rul.g_w = clip_X1 - rul.g_x) > w)
  504.         rul.g_w = w;
  505.     else
  506.     if (rul.g_w <= 0) return;
  507.  
  508. /*
  509.     rul.g_y = world_rc_y(y);
  510.     h    = world_rc_y(h) + 1;
  511. */
  512.     rul.g_y = worldy(y);        /* CJG 11/07/89 */
  513.     h    = worldy(h) + 1;
  514.  
  515.     if (rul.g_y < clip_Y0) {
  516.         ref = clip_Y0 - rul.g_y;
  517.         rul.g_y = clip_Y0;
  518.     }
  519.     else    ref = 0;
  520.     h    -= ref;
  521.     if (h <= 0)    return;
  522.     if ((rul.g_h = clip_Y1 - rul.g_y) > h)
  523.         rul.g_h = h;
  524.     else
  525.     if (rul.g_h <= 0) return;
  526.  
  527.     rast_op(15,&rul,orect_MFDB,&rul,orect_MFDB);
  528. }
  529.  
  530. /****************************************/
  531. /*    X world value to X R.C value    */
  532. /****************************************/
  533.  
  534. world_convert(x)
  535. unsigned x;
  536. {
  537.    switch(zrat)
  538.    {
  539.     case 100:
  540.        if(sdevm == 3)
  541. /*        return(world_rc_x(x));*/
  542.         return(worldx(x));    /* CJG 11/07/89*/
  543.        else
  544.         return(mu_array[x]);
  545.        break;
  546.     case 50:
  547.        x /= 2;
  548.        return(mu_array[x]);
  549.        break;
  550.     case 75:
  551.        x *= 3;
  552.        x /= 4;
  553.        return(mu_array[x]);
  554.        break;
  555.     default:
  556. /*       return(world_rc_x(x));*/
  557.        return(worldx(x));        /* CJG 11/07/89 */
  558.        break;
  559.    }
  560. }
  561.  
  562. world_rc_x(x)
  563. unsigned x;
  564. {
  565. /*
  566.     ULG    temp;
  567.     x = zvalue(x);
  568.     temp = (ULG)xdpi[sdevm] * (ULG)x;
  569.     x = ((temp % 1296L) > 648L);
  570.     temp /= 1296L;
  571.     return((unsigned)temp + x);
  572. */
  573.     return(worldx(x));    /* CJG 11/07/89 */
  574. }
  575.  
  576. /****************************************/
  577. /*    Y world value to Y R.C value    */
  578. /****************************************/
  579. world_rc_y(y)
  580. unsigned y;
  581. {
  582. /*
  583.     ULG    temp;
  584.     y = zvalue(y);
  585.     temp = (ULG)ydpi[sdevm] * (ULG)y;
  586.     y = ((temp % 1152L) > 576L);
  587.     temp /= 1152L;
  588.     return((unsigned)temp + y);
  589. */
  590.     return(worldy(y));    /* CJG 11/07/89 */
  591. }
  592.  
  593. /****************************************
  594. *    Zoom value convert function    *
  595. ****************************************/
  596. /*
  597. zvalue(n)
  598. unsigned n;
  599. {
  600.     ULG    temp;
  601.     if (zrat == 100) return(n);
  602.     temp = (ULG)zrat * (ULG)n;
  603.     n = ((temp % 100L) > 50L);
  604.     temp /= 100L;
  605.     return((unsigned)temp + n);
  606. }
  607. */
  608.  
  609.  
  610. resetIFpos()
  611. {
  612.         lastmuy = lastpixy = 0;
  613.     last_y        = 0L;
  614.     present.x    = H_MARGIN,
  615.     present.y    = V_MARGIN;    /* reset the text positions    */
  616.     present.reverse = 0,
  617.     present.rev_top = 0,
  618.     present.rev_bot = 0;        /* init reverse type OFF    */
  619.     rvo.ch        = 0;
  620.     rvo.py        = present.y;
  621. }
  622.  
  623.  
  624. setYpos(ypos)
  625. unsigned ypos;
  626. {
  627.     present.y = ypos;
  628.     rvo.py      = present.y;
  629. }
  630.  
  631.